<?PHP

if(phpversion() < 5){ require_once(TEMPLATEPATH.'/op/functions.php4.php'); }
require_once(TEMPLATEPATH.'/op/auth.OP.php');
require_once(TEMPLATEPATH.'/op/admin/layout_selector.php');
require_once(TEMPLATEPATH.'/op/admin/widgets_admin.php');
require_once(TEMPLATEPATH.'/op/class.OP.php');
require_once(TEMPLATEPATH.'/op/modules/module.wordpress.php');

global $OnePress;
$OnePress = new OP();

add_action('wp_authenticate','op_auth_init',10,2);
add_action('wp_logout','op_logout');
add_action('register_post', 'op_wp_userExists',10,3);

//  Serve appropriate comment template based on WP version
add_filter('comments_template', 'old_comments');

function old_comments($file) {
	if(!function_exists('wp_list_comments')) 	$file = TEMPLATEPATH . '/comments_old.php';
	return $file;
}

global $pagenow;
if ( ($pagenow == "wp-login.php" || $pagenow == 'profile.php')  && $_GET['action'] != 'logout' && !isset($_GET['key']) ) {
	add_action('init',array('op_WordPress','op_init'));
}

// AJAX Actions
add_action('wp_ajax_op_featurecarousel_remove_tag', array('OP_FeatureCarouselWidget','remove_tag') );

// Layout selector AJAX actions...  FIXME -- can these be moved elsewhere?
add_action('wp_ajax_op_layoutselector_buildcolumn', array('OP_Layout_Selector_Interface','ajax_build_column'));
add_action('wp_ajax_op_layoutselector_customize', array('OP_Layout_Selector_Interface','ajax_customize'));
add_action('wp_ajax_op_layoutselector_savestate', array('OP_Layout_Selector_Interface','ajax_save_state'));
add_action('wp_ajax_op_img_get', array('OP_ImageSelection','get_images'));

add_action('wp_ajax_op_widgetsadmin', array('OP_WidgetsAdmin','controller'));

add_action('wp_ajax_op_upgrademodule', array('OP_Modules','upgrade'));

add_action('admin_menu', 'OP_theme_options');
//add_action('wp_head','wp_print_styles',5);
//add_action('init','OP_init_head');

function OP_theme_options() {
	
	$mypage = add_submenu_page('themes.php','OnePress Layout', 'OnePress Layout',9,'layout_selector',array('OP_Layout_Selector_Interface','layout_selector'));
	add_action( "admin_print_styles-$mypage", array('OP_Layout_Selector','add_styles') );
	
	require_once(TEMPLATEPATH.'/op/admin/admin_settings.php');
	$mypage = add_submenu_page('options-general.php','OnePress', 'OnePress',9,'admin_settings',array('OP_Admin_Settings','construct'));
	add_action( "admin_print_styles-$mypage", array('OP_Admin_Settings','add_styles') );
}

if(!function_exists('is_sidebar_active')){
function is_sidebar_active( $name = 1 ){
	global $wp_registered_sidebars;
	foreach($wp_registered_sidebars as $k => $v){
		if($v['name'] == $name) $sidebar_id = $k;
	}
	$sidebars = wp_get_sidebars_widgets();
	
	return (isset($sidebars[$sidebar_id]));
}
}

?>